package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.ReportPlanChangeModel;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.BuyPlanChangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 采购管理 -> 采购计划变更
 * 查看 -> buy:buychange:view
 * 编辑 -> buy:buychange:edit
 *
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/buyPlanChange")
public class BuyPlanChangeController extends BaseController {

    @Autowired
    private BuyPlanChangeService service;

    /**
     * 采购计划变更页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"buy:buychange:view"})
    public String project() {
        return "buy/buyPlanChange/page";
    }

    /**
     * 采购计划变更列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"buy:buychange:view"})
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findBuyPlanChangeListByQuery(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 采购计划变更
     *
     * @param shoppingPlanModel 变更对象
     * @return json
     */
    @ResponseBody
    @PostMapping("/change")
    @RequiresPermissions({"buy:buychange:edit"})
    public JsonResult change(ShoppingPlanModel shoppingPlanModel) {
        return jsonResult(service.changeBuyPlan(shoppingPlanModel));
    }

    /**
     * 采购计划变更列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list/{id}")
    @RequiresPermissions({"buy:buychange:view"})
    public JsonResult list(@PathVariable("id") Integer id) {
        startPage();
        List<ReportPlanChangeModel> list = service.findReportPlanChangeList(id);
        return jsonResult(list);
    }

    /**
     * 查询采购计划为合报的相应提报计划变更是否有变更物料的
     *
     * @param shoppingPlanModel 采购计划
     * @return json
     */
    @ResponseBody
    @PostMapping("/status")
    @RequiresPermissions({"buy:buychange:edit"})
    public boolean status(ShoppingPlanModel shoppingPlanModel) {
        return service.selectStatus(shoppingPlanModel);
    }
}
